local ma__junzhi = fk.CreateSkill {
  name = "ma__junzhi",
}

Fk:loadTranslationTable{
  ["ma__junzhi"] = "均治",
  [":ma__junzhi"] = "出牌阶段限一次，你可以令至多X名手牌数各不相同的角色摸一张牌(X为你的体力值)，然后你依次获得其中手牌数大于体力值的角色的一张牌。",

  ["#ma__junzhi"] = "均治：令至多%arg名手牌数不同的角色摸一张牌，你获得其中手牌数大于体力值的角色各一张牌",
  ["#ma__junzhi-get"] = "均治：请选择获得 %dest 的一张牌",
}

ma__junzhi:addEffect("active", {
  anim_type = "control",
  prompt = function (self, player, selected_cards)
    return "#ma__junzhi:::"..player.hp
  end,
  card_num = 0,
  min_target_num = 1,
  max_target_num = function (self, player)
    return player.hp
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(ma__junzhi.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    if #selected < player.hp and not to_select:isRemoved() then
      if #selected == 0 then
        return true
      else
        for _, p in ipairs(selected) do
          if p:getHandcardNum() == to_select:getHandcardNum() then
            return false
          end
        end
        return true
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local targets = table.simpleClone(effect.tos)
    room:sortByAction(targets)
    for _, p in ipairs(targets) do
      if not p.dead then
        p:drawCards(1, ma__junzhi.name)
      end
    end
    local target = table.filter(targets, function(p)
      return not p.dead and p ~= player and p:getHandcardNum() > p.hp
    end)
    if #target < 1 then return end
    for _, to in ipairs(target) do
      local card = room:askToChooseCard(player,{
        target = to,
        flag = "he",
        skill_name = ma__junzhi.name,
        prompt = "#ma__junzhi-get::"..to.id,
        cancelable = false,
      }
    )
    room:obtainCard(player, card, false, fk.ReasonPrey, player, ma__junzhi.name)
    end
  end,
})

return ma__junzhi